package com.proj.mhl.service;

import com.proj.mhl.dao.DiningTableDAO;
import com.proj.mhl.domain.DiningTable;

import java.util.List;

public class DiningTableService {
    //DAO
    private DiningTableDAO diningTableDAO = new DiningTableDAO();

    //select all
    public List<DiningTable> selectAllTable() {
        return diningTableDAO.queryMulti("select id,state from diningTable where id >= ?", DiningTable.class, 1);
    }

    //select Single
    public DiningTable selectSingleTab(Integer id) {
        return diningTableDAO.querySingle("select state from diningTable where id = ?", DiningTable.class, id);

    }

    //order
    public boolean orderTable(Integer id, String order_name, String orderTel) {

        int update =
                diningTableDAO.update(" UPDATE diningTable SET state = '已预定',orderName = ?,orderTEl = ? WHERE id = ?", order_name, orderTel, id);
        return update > 0;
    }

    //订单提供状态，更新餐桌状态
    public boolean updateDiningTableState(int id, String state) {
        int update = diningTableDAO.update("update diningTable set state = ? where id = ?", state, id);
        return update > 0;//大于0 即更新成功
    }

    //设置餐桌为空闲状态
    public boolean updateDiningTableStateToFree(int id) {
        int update = diningTableDAO.update("update diningTable set state = '空',orderName='',orderTEl ='' where id = ?", id);
        return update > 0;//大于0 即更新成功
    }
}
